/**
 * 文件：ChoiceView.java
 * 包名：com.ronri.ams.sample;   --- 正式发布时需要修正
 * 说明：单选VIEW
 * 作者：MS During
 * 日期：2017/5/11
 * 历史：
 */
package com.ronri.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cz.nongyetongv5.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ChoiceViewAdapter extends BaseAdapter {

    private List<Map<String, Object>> mItems = new ArrayList<Map<String, Object>>();

    private Context mContext;

    public ChoiceViewAdapter(Context context, List<Map<String, Object>> data) {
        super();

        mItems = data;
        mContext = context;
    }

    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public String getItem(int position) {

        for (Map.Entry<String, Object> entry : mItems.get(position).entrySet()) {
            if(entry.getKey() == "listTitle"){
                return entry.getValue().toString();
            }
        }
        return "";
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup container) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.v_item, null);

            convertView.setTag(mItems.get(position));
        }

        ((TextView) convertView.findViewById(R.id.listTitle))
                .setText(getItem(position));

        return convertView;
    }
}
